package net.flyinggroup.observability;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@SpringBootApplication
public class LinOteljzApplication {
    public static void main(String[] args) {
        SpringApplication.run(LinOteljzApplication.class, args);
    }

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder builder) {
        return builder.build();
    }

    @RestController
    class HelloController {
        private final RestTemplate restTemplate;

        public HelloController(RestTemplate restTemplate) {
            this.restTemplate = restTemplate;
        }

        @GetMapping("/hello")
        public String hello() {
            ResponseEntity<String> response = restTemplate.postForEntity("https://httpbin.org/post", "hello!", String.class);
            return response.getBody();
        }
    }
}